package com.lib724.web.controller;

import java.util.HashMap;
import java.util.Map;

import com.javaeedev.lightweight.mvc.ActionContext;
import com.javaeedev.lightweight.mvc.ModelAndView;
import com.lib724.model.User;

/**
 * Register a new user.
 * 
 * @author Xuefeng
 */
public class RegisterAction extends AbstractAction {

    private String username;
    private String password;
    private String email;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public ModelAndView execute() throws Exception {
        if("GET".equals(ActionContext.getActionContext().getRequest().getMethod()))
            return new ModelAndView("register");
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setEmail(email);
        facade.createUser(user);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user", user);
        return new ModelAndView("register_ok", map);
    }

}
